package com.example.tliasmanagement.controller;

import com.example.tliasmanagement.dto.AddStudentDto;
import com.example.tliasmanagement.dto.StudentListDto;
import com.example.tliasmanagement.dto.UpdateStudentDto;
import com.example.tliasmanagement.entity.Student;
import com.example.tliasmanagement.service.StudentService;
import com.example.tliasmanagement.vo.PageBean;
import com.example.tliasmanagement.vo.Result2;
import com.example.tliasmanagement.vo.StudentListVo;
import com.example.tliasmanagement.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    /* *
     * 学生列表分页查询
     *
     * */
    @GetMapping("/students")
    public Result2<PageBean<StudentListVo>> students(StudentListDto dto){
        PageBean<StudentListVo> pageBean = studentService.students(dto);
        return Result2.ok(pageBean);
    }
    /**
     * 查询班级
     *
     */
    @GetMapping("/clazzs/list")
    public Result2<List<StudentVo>> getClazzName(){
        List<StudentVo> list = studentService.getClazzNames();
        return Result2.ok(list);
    }
    /**
     * 新增学员
     *
     */
    @PostMapping("/students")
    public Result2 addStudent(@RequestBody AddStudentDto dto){
        studentService.addStudent(dto);
        return Result2.ok();
    }
    /**
     * 删除学员
     *
     */
    @DeleteMapping("/students")
    public Result2 deleById(@RequestParam("ids")List<Integer>ids){
        studentService.deleteById(ids);
        return Result2.ok();
    }
    /**
     * 根据ID查询学员
     *
     */
    @GetMapping("/students/{id}")
    public Result2<Student> getById(@PathVariable("id") Integer id){
        Student student = studentService.getById(id);
        return Result2.ok(student);
    }
    /**
     * 修改学员
     *
     */
    @PutMapping("/students")
    public Result2 updateStudent(@RequestBody UpdateStudentDto dto){
        studentService.updateStudent(dto);
        return Result2.ok();
    }
    /**
     * 违纪处理
     *
     */
    @PutMapping("/students/violation/{id}/{score}")
    public  Result2 updateScore(@PathVariable("id") Integer id,@PathVariable("score")Integer score){
        studentService.updateScore(id,score);
        return Result2.ok();
    }


}
